package main

import (
"net"
"fmt"
"os"
)

func main() {
	addr := net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 5004}
	paddr := net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 5005}
	con, err := net.ListenUDP("udp", &addr)
	pcon, perr := net.DialUDP("udp", nil, &paddr)

	if err != nil || perr != nil {
		fmt.Print("Connection error.", err)
	}

	defer pcon.Close()
	defer con.Close()
	for {
		proxy25005(con, pcon)
	}
}
func proxy25005(conn, pcon *net.UDPConn) {
	data := make([]byte, 2048)

	n, _, err := conn.ReadFromUDP(data)
	if err != nil {
		fmt.Print("Connection error:", err)
		os.Exit(1)
	}

	//fmt.Printf("%s\n", data[:n])

	n, err = pcon.Write(data[:n])

	if err != nil {
		//fmt.Println("Connection error:", err)
	} else{
		fmt.Println("Send pakcet length:",n)
	}

}

